import request from "@/utils/request";
import localData from "kuan-utils/lib/localData";

const { get, set } = localData;

const aliKey = "merchant-UPLOAD_TOKEN_ALI";
const qnKey = "merchant-UPLOAD_TOKEN_QN";

/**
 * @param {Boolean} isPrivate
 */
export async function qnToken() {
  const key = qnKey;
  const localToken = get(key);
  if (localToken) return localToken;
  const { token } = await request({
    url: "/api/merchant-dashboard/v1/upload/token"
  });
  set(key, token, 60 * 24);
  return token;
}

/**
 * 阿里云上传token
 */
export async function aliToken() {
  const localToken = get(aliKey);
  if (localToken) return localToken;

  const res = await request({
    url: "/api/dashboard/v1/uptoken"
  });

  set(aliKey, res, 60 * 24);
  return res;
}
